package com.neuronbit.businessflow.flow.parser;

import com.neuronbit.javaparser.resolution.types.ResolvedType;
import lombok.Getter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import static org.apache.commons.lang3.StringUtils.capitalize;

/**
 * The type Output.
 */
@Getter
@ToString(callSuper = true)
public class Output {
    private final String name;
    private final String description;
    private final ResolvedType type;

    /**
     * Instantiates a new Output.
     *
     * @param name        the name
     * @param description the description
     * @param type        the type
     */
    public Output(String name, String description, ResolvedType type) {
        this.name = name;
        this.description = description;
        this.type = type;
    }

    /**
     * Gets type name.
     *
     * @return the type name
     */
    public String getTypeName() {
        if (type.isVoid()) {
            return "Void";
        }

        return type.describe();
    }

    /**
     * Is simple type boolean.
     *
     * @return the boolean
     */
    public boolean isSimpleType() {
        if (null == type) {
            return true;
        }
        if (StringUtils.startsWithAny(type.describe(), "java.lang", "java.math")) {
            return true;
        }
        if (!type.describe().contains(".")) {
            return true;
        }
        return false;
    }

    /**
     * Gets capitalize name.
     *
     * @return the capitalize name
     */
    public String getCapitalizeName() {
        return capitalize(name);
    }
}
